//
//  WSPayUrlViewController.m
//  FD
//
//  Created by xiaofang wang on 2018/11/29.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "WSPayUrlViewController.h"
#import <WebKit/WebKit.h>
//1-9往这跳
#import "FDTabBarController.h"

@interface WSPayUrlViewController ()<WKNavigationDelegate>
/**网页*/
@property (nonatomic, strong) WKWebView *webView;

/**hud*/
@property (nonatomic, strong) MBProgressHUD *hud;
@end

@implementation WSPayUrlViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    [self setupNav];
}

- (void)setupNav {
    
    //点返回按钮跳转到订单列表页面
    UIButton *backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [backBtn setImage:[UIImage imageNamed:@"返回箭头.png"] forState:(UIControlStateNormal)];
    [backBtn addTarget:self action:@selector(backAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    backBtn.frame = CGRectMake(0, 0, 40, 30);
    backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); //1-3
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}


//点返回按钮跳转到订单列表页面
- (void)backAction:(UIButton *)button {
//    WaiSongViewController *wsVC = [[WaiSongViewController alloc] init];//
////    [self.navigationController popToRootViewControllerAnimated:YES];
//    [self.navigationController popViewControllerAnimated:YES]; //
//    [self.navigationController popToViewController:wsVC animated:YES]; //跳死了
    
    //跳转支付订单页面
    [self.navigationController popToRootViewControllerAnimated:NO];
    FDTabBarController *tabvC = [FDTabBarController shareFDTabarVC];
    tabvC.selectedIndex = 2;
    [UIApplication sharedApplication].keyWindow.rootViewController = tabvC;
}

- (void)setupUI {
    self.view.backgroundColor = [UIColor greenColor];
    
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    
    WKWebView *webViewe = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
    
    NSURL *url = [NSURL URLWithString:self.payUrl];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    [webViewe loadRequest:request];
    
    webViewe.navigationDelegate = self;
    
    self.webView = webViewe;
    [self.view addSubview:self.webView];
    
    //记载中
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}


#pragma mark  - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {

    [self.hud hideAnimated:YES];
}

@end

